package com.mysafe.provision.view.account;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import com.mysafe.provision.exception.ValidationException;
import com.mysafe.provision.service.account.IAccountService;
import com.mysafe.provision.view.login.LoginScreen;

@Named
@RequestScoped
public class CreateAccountScreen implements Serializable {

	private static final long serialVersionUID = 2043416665834898467L;
	
	private LoginScreen login;
	private IAccountService accountService;

	public CreateAccountScreen() {
	}
	
	@Inject
	public CreateAccountScreen(IAccountService accountService, LoginScreen login) {
		this.accountService = accountService;
		this.login = login;
	}

	public String createAccount() {
		String outcome = "created";
		try {
			accountService.createAccount(login.getAccount());
			login.getAccount().setLogged(true);
		} catch (ValidationException e) {
			outcome = "error";
		}
		return outcome;
	}

	public LoginScreen getLogin() {
		return login;
	}

	public void setLogin(LoginScreen login) {
		this.login = login;
	}

}